package com.baizhi.action;

import com.baizhi.entity.City;
import com.baizhi.entity.Tag;
import com.baizhi.service.CityService;
import com.baizhi.service.impl.CityServiceImpl;
import com.baizhi.service.impl.TagServiceImpl;
import com.baizhi.service.tagService;
import com.opensymphony.xwork2.ActionSupport;

import java.util.List;

public class CityAction extends ActionSupport {
    //城市对象
    private City city;
    private int id;
    private List<City> citys;
    private int totalPage; //总页数
    //接收数据   页号
    private int pageNumber=1;



    //分页查询
    public String findByPage(){

        //调用业务
        CityService cs = new CityServiceImpl();
        //1、根据页号查询数据
        System.out.println(pageNumber);
        citys = cs.queryByPage(pageNumber);
        //2、获取总页数
        totalPage = cs.getTotalPage();
        System.out.println(totalPage);

        //跳转页面
        return "successSelectByPage";
    }



    //添加城市
   public String insertCity(){

       CityService cs =new CityServiceImpl();
       cs.insertCity(city);

       return "insertsuccess";
   }



    //删除城市
    public String deleteCity(){

        CityService cs =new CityServiceImpl();
        cs.deleteById(id);
       return "delectsuccess";
    }


    //查询所有城市
    public String queryAllCitys(){

        CityService cs =new CityServiceImpl();
        citys = cs.queryAll();

        return "queryAllsuccess";
    }





    //get/set
    public int getTotalPage() {
        return totalPage;
    }

    public void setTotalPage(int totalPage) {
        this.totalPage = totalPage;
    }

    public int getPageNumber() {
        return pageNumber;
    }

    public void setPageNumber(int pageNumber) {
        this.pageNumber = pageNumber;
    }

    public City getCity() {
        return city;
    }

    public void setCity(City city) {
        this.city = city;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public List<City> getCitys() {
        return citys;
    }

    public void setCitys(List<City> citys) {
        this.citys = citys;
    }
}
